package com.yanqu.road.logic.config;

import com.yanqu.road.dao.impl.config.AreaConfigDaoImpl;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.HashMap;

/**
 * 跨域服务器配置
 */
public class AreaServerConfig {
    private static final Logger logger = LogManager.getLogger(AreaServerConfig.class.getName());

    @ConfigPropertyAnnotation(key = "CLICKHOUSE_LOG_SERVER_URL", description = "clickhouse日志服务地址", type = String.class, defaultValue = "")
    public static String CLICKHOUSE_LOG_SERVER_URL;

    @ConfigPropertyAnnotation(key = "CLICKHOUSE_LOG_SERVER_SWITCH", description = "clickhouse日志区服上报开关 0关1开默认开", type = Integer.class, defaultValue = "1")
    public static int CLICKHOUSE_LOG_SERVER_SWITCH;

    public static void reloadAreaServerConfig(long areaServerId) {
        logger.info("reload area server config! AreaServerId: {}", areaServerId);

        HashMap<String, String> configs = new AreaConfigDaoImpl().getChannelConfig(areaServerId);
        if (!configs.isEmpty()) {
            TempConfig.Load(AreaServerConfig.class, configs);
        }

    }
}
